﻿package net.wangit.view.element.component;

import net.wangit.MapList;
import net.wangit.Page;
import net.wangit.Row;
import net.wangit.context.ActionContext;
import net.wangit.support.ElementWriter;
import net.wangit.util.Checker;
import net.wangit.view.element.ElementComponent;
import net.wangit.view.enumeration.EnumerationFactory;

public final class SelectFieldElement extends ElementComponent {

	private static final ElementWriter writer = new SelectFieldElementWriter();
	private String enumerationId;

	public SelectFieldElement() {
	}

	public SelectFieldElement(String id, MapList enumeration) {
		setId(id);
		setObject(enumeration);
	}

	protected void configure(Row row) {
		enumerationId = row.get("r");
	}

	protected ElementWriter getWriter() {
		return writer;
	}

	protected void cloneAfter(ActionContext ac, Page page) {
		if (!Checker.isEmpty(enumerationId)) {
			String domain = parent.getDomain();
			setObject(EnumerationFactory.getEnumeration(ac, domain,
					enumerationId));
		}
	}

}
